package com.binge.test3;

import com.binge.batis.reflection.ParamNameResolver;
import com.binge.batis.reflection.TypeParameterResolver;
import com.binge.batis.reflection.property.PropertyCopier;
import com.binge.batis.reflection.property.PropertyTokenizer;
import com.binge.test3.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.Configuration;
import org.junit.Test;

import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:CoreTest
 * Package:com.binge.test3
 * Description:
 *
 * @Author @Bin
 * @Date 2023/10/23-14:39
 * @Version: v1.0
 */
@Slf4j
public class CoreTest {


    @Test
    public void test1() {
        Map<String,HashMap<String,String>> hashMap = new HashMap<>();
        HashMap<String,String> hashMap1 = new HashMap<>();
        hashMap1.put("a1","av1");
        hashMap1.put("a2","av2");
        hashMap.put("1",hashMap1);
        HashMap<String,String> hashMap2 = new HashMap<>();
        hashMap2.put("b1","av2");
        hashMap2.put("b2", "av2");
        hashMap.put("2",hashMap2);
    }


    @Test
    public void test2() {
        User user1 = new User();
        user1.setName("binge");
        user1.setAge(18);

        User user2 = new User();
        PropertyCopier.copyBeanProperties(User.class,user1,user2);
        log.info("user2:{}",user2);
        log.info("user1:{}",user1);

    }

    @Test
    public void test7() {
        Type[] types = TypeParameterResolver.resolveParamTypes(Arrays.stream(CoreTest.class.getMethods()).filter(method -> method.getName().equalsIgnoreCase("test3")).findAny().get(), CoreTest.class);
        for (Type type : types) {
            log.info("type:{}",type);
        }
    }



    public void test3(String name,Integer age) {
        PropertyTokenizer propertyTokenizer = new PropertyTokenizer("student[sId].name");
        log.info("name:{}",propertyTokenizer.getName());
        log.info("index:{}",propertyTokenizer.getIndex());
        log.info("indexedName:{}",propertyTokenizer.getIndexedName());
    }


    @Test
    public void test4() {
        ParamNameResolver paramNameResolver = new ParamNameResolver(new Configuration(), Arrays.stream(CoreTest.class.getMethods()).filter(method -> method.getName().equals("test3")).findAny().get());

        Object namedParams = paramNameResolver.getNamedParams(new Object[]{"binge", 18});
        log.info("namedParams:{}",namedParams);
    }

}
